/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package backstage.product;



import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import shops.ProductItem_Back;
/**
 *
 * @author Gjun
 */
public class changeUpdate {
    
    //private int checkid;
   // private int checkid_2;
    private int id;
    private int updateId;    
//輸出至前端網頁
    private String title; 
    private shops.ProductItem_Back productItem_Back;  
    private TreeMap<Integer,String> typeResult;
    private TreeMap<Integer,String> supplyResult;
        
   
    public String execute() throws Exception {
     
        NWDB.NWDB mydb=new NWDB.NWDB();
        NWDB.IProduct ip=new NWDB.ImplProduct(mydb.getConnection());
        mydb.setIProduct(ip);
        
        HttpServletRequest request=ServletActionContext.getRequest();         
       // checkid=mydb.GetAllProductCount();
      //checkid_2=Integer.parseInt(request.getParameter("id"));
      // System.out.println(request.getParameter("id"));
            this.setTitle("修改產品");        
            HashMap<String,Object> hm=mydb.GetProductItemById_Back(updateId);            
            this.productItem_Back=new shops.ProductItem_Back();
            this.productItem_Back.setId((Integer)hm.get("changeId"));
            this.productItem_Back.setName(hm.get("name").toString());
            this.productItem_Back.setPrice((Integer)hm.get("price"));
            this.productItem_Back.setStock((Integer)hm.get("stock"));
            this.productItem_Back.setSale((Byte)hm.get("sale"));
            this.productItem_Back.setTypeId((Integer)hm.get("typeId"));
            this.productItem_Back.setTypeName(hm.get("typeName").toString());
            this.productItem_Back.setClick_count((Integer)hm.get("click_count"));
            this.productItem_Back.setDescription(hm.get("description").toString());  
     /*  this.productItem_Back.setPic((byte[])hm.get("pic"));
            this.productItem_Back.setPic_1((byte[])hm.get("pic_1"));
            this.productItem_Back.setPic_2((byte[])hm.get("pic_2"));
            this.productItem_Back.setPic_3((byte[])hm.get("pic_3"));
     */
        this.typeResult=mydb.GetProductType();
    
        mydb.close();        
        return "success";        
    }

    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    
    public TreeMap<Integer,String> getTypeResult() {
        return typeResult;
    }
    public void setTypeResult(TreeMap<Integer,String> typeResult) {
        this.typeResult = typeResult;
    }

    public TreeMap<Integer,String> getSupplyResult() {
        return supplyResult;
    }
    public void setSupplyResult(TreeMap<Integer,String> supplyResult) {
        this.supplyResult = supplyResult;
    }   
   
   public ProductItem_Back getProductItem_Back() {
        return productItem_Back;
    }

    public void setProductItem_Back(ProductItem_Back productItem_Back) {
        this.productItem_Back = productItem_Back;
    }

    public int getUpdateId() {
        return updateId;
    }

    public void setUpdateId(int updateId) {
        this.updateId = updateId;
    }

   
 
}
